;;;; 2007-09-08 12:04:17
;;;; Data access implementation

(in-package :gtcup)

;; You must create an instance of this class to appropriate values. 
(defclass database-connection ()(
  (driver 
   :accessor database-type
   :documentation "driver name: :mysql"
   :initarg :driver)
  (server 
   :accessor database-server
   :documentation "The name of the database server if required"
   :initarg :server)
  (name 
   :accessor database-name
   :documentation "The name of the database we will work in"
   :initarg :name)
  (user 
   :accessor database-user
   :documentation "The name of the database user we will work as"
   :initarg :user)
  (password 
   :accessor database-password
   :documentation "The password if required"
   :initarg :password)))


;; Methods
;; Connect to the database (see the CLSQL documentation for vendor
;; specific connection specs).

(defgeneric connect-to-db (self))

(defmethod connect-to-db ((self database-connection))
  (clsql:connect 
   (list (database-server self) 
	 (database-name self) 
	 (database-user self) 
	 (database-password self))
   :database-type (database-type self)))

(defun create-database-connection (server name user password)
  (make-instance 'database-connection
		 :driver :mysql
		 :server server
		 :name name
		 :user user
		 :password password))
